/* eslint valid-jsdoc: "off" */
/* eslint-disable */

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1732525689306_483';

  // add your middleware config here
  config.middleware = ['checkToken'];
  // 配置路由匹配规则
  const matchConfig = {
    '/login': [],
    '/register': [],
    '/generateCode': [],
    '/validateCode': [],
    '/admin/login': [],
    '/admin/register': [],
    // '/food': ['GET'],
    // '/shop': ['GET'],
    // '/share': ['GET'],
  };
  config.checkToken = {
    match(ctx) {
      console.log(ctx.request)
      const url = ctx.request.url
      const method = ctx.request.method.toUpperCase()
      const noCheck = matchConfig[url] && (matchConfig[url].length === 0 ||
        matchConfig[url].includes(method))
      if (noCheck) {
        return false
      }
      return true
    }
  }
  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  config.cluster = {
    listen: {
      path: '',
      port: 8888,
      hostname: '0.0.0.0',
    },
  };
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };
  config.jwt = {
    secret: 'egg.js jwt plugin',
  };
  config.security = {
    csrf: {
      // enabled: false
      ignore: (ctx) => true,
    },
  };
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    database: 'fashion_db',
    username: 'root',
    password: '',
    timezone: '+08:00',
  };
  config.validatePlus = {
    resolveError(ctx, errors) {
      if (errors.length) {
        ctx.type = 'json';
        ctx.status = 400;
        ctx.body = {
          code: 400,
          error: errors,
          message: '参数错误',
        };
      }
    },
  };
  config.bcrypt = {
    saltRounds: 10,
  };
  
  config.multipart={
    fileSize:'20mb'
  };
  return {
    ...config,
    ...userConfig,
  };
};
